<template>
	<view>
		<view class="logo-zfb">
			<image :src="require('@/static/img/main/my/assets/zfb.jpg')" mode="widthFix"></image>
		</view>
		<!-- 1，未绑定 -->
		<view class="binding" v-if="!isBinding">
			<view class="title">
				<view>请确认将要绑定的账号为本人所有</view>
				<view>支付宝账号将作为你在支付安全中的认证信息</view>
			</view>
			<view class="btn" @click="gotozfb">
				<text>立即绑定</text>
			</view>
			<!-- <binding-btn></binding-btn> -->
		</view>
		<view class="binding" v-else>
			<view class="title">
				<view class="title-black">当前已绑定</view>
				<view>支付宝账号：
					<text class="phone">{{phone}}</text>
				</view>
			</view>
			<view class="btn" @click="gotoSecureBinding">
				<text>解绑</text>
			</view>
		</view>
	</view>

	</view>
</template>

<script>
	import {
		queryIsBinding
	} from '@/api/http/main/my/community.js'

	import bindingBtn from './child/binding-btn.vue'

	export default {
		components:{
			bindingBtn
		},
		data() {
			return {
				isBinding: false,
				phone: ''
			}
		},
		methods: {
			//1，查询是否绑定过
			queryIsBinding() {
				var that = this
				queryIsBinding().then(res => {
					if (res.data.pubInfo.code !== 0) {
						return uni.$showMsg(res.data.pubInfo.message);
					}
					//2.3，参数保存
					this.isBinding = res.data.busInfo.isBinding
					//console.log(this.isBinding)
					this.phone = res.data.busInfo.phone
				})
			},

			//跳转支付宝绑定
			gotozfb() {
				if (this.isBinding) {
					return uni.$showMsg('无法重复绑定提现账号！');
				}
				uni.navigateTo({
					url: '/subpkg/main/my/assets/binding/bdtx-zfb/bdtx-zfb'
				})

				/* let appId = '202100118361107'
				let scope = 'auth_userinfo'
				let redirectUrl = 'http://47.106.223.49/demo3.html'
				let androidPrefix = 'alipays://platformapi/startapp?appId=20000067&url='
				let iosPrefix = 'alipay://platformapi/startapp?appId=20000067&url='

				let urls = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?appId=" + appId +
					"&scope" + scope +
					"&redirect_uri=" + redirectUrl
				urls = encodeURIComponent(urls) //将地址编码为浏览器访问格式

				//判断平台
				if (plus.os.name == 'Android') {
					let openURL = androidPrefix + urls;
					//console.log("openURL:" + openURL);
					plus.runtime.openURL(openURL, err => {
						uni.showToast({
							title: "打开支付宝失败！请检查是否已安装？",
							icon: 'none'
						})
					}, 'com.eg.android.AlipayGphone')
				} else if (plus.os.name == 'iOS') {
					let openURL = iosPrefix + urls;
					plus.runtime.openURL(openURL, err => {
						uni.showToast({
							title: "打开支付宝失败！请检查是否已安装？",
							icon: 'none'
						})
					}, 'com.eg.android.AlipayGphone')
				}*/

			},
			//解除支付宝绑定
			gotoSecureBinding() {
				if (!this.isBinding) {
					return uni.$showMsg('还没有绑定过账号！');
				}
				uni.navigateTo({
					url: '/subpkg/main/my/assets/binding/secure-binding/secure-binding'
				})
			}
		},
		onLoad() {
			this.queryIsBinding()
		}
	}
</script>

<style scoped lang="scss">
	.logo-zfb {
		text-align: center;

		image {
			width: 60%;
		}
	}

	.binding {
		margin-top: 50rpx;

		.title {
			view {
				text-align: center;
				font-size: 32rpx;
				color: #B0B0B0;
				margin: 10rpx;
			}


			.title-black {
				color: #333;
			}

			.phone {
				color: #5D7FDF;
			}
		}

		.btn {
			width: 60%;
			height: 100rpx;
			margin-top: 40rpx;
			margin-left: 20%;
			border-radius: 60rpx;
			text-align: center;
			line-height: 100rpx;
			background-color: #4F7FFD;

			text {
				color: #fff;
				font-size: 32rpx;
			}
		}
	}
</style>